<template>
  <div class="app-container">
    <el-form :inline="true">
      <el-form-item label="行业名称">
        <el-input
          v-model="queryParams.hwType"
          placeholder="请输入行业名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="版本列表">
        <el-select v-model="queryParams.versions" placeholder="请选择版本列表" clearable size="small">
          <el-option
            v-for="dict in businessVersionsList"
            :key="dict"
            :label="dict"
            :value="dict"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          class="filter-item"
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索</el-button>
        <!-- <el-button
          class="filter-item"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd()"
          v-hasPermi="['system:dept:add']"
        >新增</el-button> -->
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="hazwasteList"
      stripe :header-cell-style="{background:'#e1f0ff',color:'#000000','margin-top':'22px','height':'48px'}" :cell-style="{'height':'46px','boder-bottom':'0px','padding':'9px 0px'}"
    >
      <!-- row-key="" -->
      <el-table-column type="expand">
        <template slot-scope="props">
          <div class="hazwasteDetail">
            <div class="hazwasteDetail_optionsTitle">
              <div class="hazwasteDetail_optionsTitleOptions" style="width:40%">行业来源</div>
              <div class="hazwasteDetail_optionsTitleOptions" style="width:10%">废物代码</div>
              <div class="hazwasteDetail_optionsTitleOptions" style="width:10%">危险废物</div>
              <div class="hazwasteDetail_optionsTitleOptions" style="width:10%">版本</div>
              <div class="hazwasteDetail_optionsTitleOptions" style="width:10%">类型</div>
              
              <div class="hazwasteDetail_optionsTitleOptions" style="width:10%">创建时间</div>
              <div class="hazwasteDetail_optionsTitleOptions" style="width:10%">操作</div>
            </div>
            <div class="hazwasteDetail_options" v-for="(item,inx) in props.row.hwBusinessSourceList" :key="inx">
              
              <div class="hazwasteDetail_optionsContent">
                <div class="optionsContent_left">{{item.businessSource}}</div>
                <div class="optionsContent_right">
                  <div class="optionsContent_rightRow" v-for="(_item,_inx) in item.hazardousWasteData" :key="_inx" >
                    <div class="optionsContent_rightOptions" style="width:16.667%">{{_item.hwCode}}</div>
                    <div class="optionsContent_rightOptions line1" style="width:16.667%" :title="_item.hwName">{{_item.hwName}}</div>
                    <div class="optionsContent_rightOptions" style="width:16.667%">{{_item.versions}}</div>
                    <div class="optionsContent_rightOptions" style="width:16.667%">{{_item.hwType}}</div>
                    <div class="optionsContent_rightOptions" style="width:16.667%">{{_item.createTime}}</div>
                    
                    <div class="optionsContent_rightOptions"  style="width:16.667%">
                      <el-button 
                        size="mini" 
                        type="text" 
                        @click="handleUpdate(_item)"
                        v-hasPermi="['system:dept:edit']"
                      >修改</el-button>
                      <!-- <el-button 
                        size="mini" 
                        type="text" 
                        @click="handleAdd(_item)"
                        v-hasPermi="['system:dept:add']"
                      >新增</el-button> -->
                      <el-button
                        size="mini"
                        type="text"
                        @click="handleDelete(_item)"
                        v-hasPermi="['system:dept:remove']"
                      >删除</el-button>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="hwType" label="废物类别"></el-table-column>
      
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="400">
        <template slot-scope="scope">
          <el-button 
            size="mini" 
            type="text" 
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:dept:edit']"
          >修改</el-button>
          <el-button 
            size="mini" 
            type="text" 
            @click="handleAdd(scope.row)"
            v-hasPermi="['system:dept:add']"
          >新增</el-button>
          <el-button
            v-if="scope.row.parentId != 0"
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:dept:remove']"
          >删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <!-- 添加或修改部门对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" :close-on-press-escape="false" :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="危废类型" prop="hwType">
              <el-input v-model="form.hwType" placeholder="请输入危废类型" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="行业来源" prop="businessSource">
              <el-input v-model="form.businessSource" placeholder="请输入行业来源" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="废物代码" prop="hwCode">
              <el-input v-model="form.hwCode" placeholder="请输入废物代码" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="危险废物" prop="hwName">
              <el-input v-model="form.hwName" placeholder="请输入危险废物" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="版本" prop="versions">
              <el-input v-model="form.versions" placeholder="请输入版本" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { hazwasteList , hazwasteDel, hazwasteAdd, hazwasteEdit, businessVersions } from "@/api/system/hazwaste";

export default {
  name: "Dept",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 表格树数据
      hazwasteList: [],
      // 部门部门树选项
      deptOptions: undefined,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        hwType: undefined,
        versions:undefined
      },
      // 表单参数
      form: {

      },
      // 表单校验
      rules: {
        hwType: [
          { required: true, message: "危废类型不能为空", trigger: "blur" }
        ],
        businessSource: [
          { required: true, message: "行业来源不能为空", trigger: "blur" }
        ],
        hwCode: [
          { required: true, message: "废物代码不能为空", trigger: "blur" }
        ],
        hwName: [
          { required: true, message: "危险废物不能为空", trigger: "blur" }
        ],
        versions: [
          { required: true, message: "版本不能为空", trigger: "blur" }
        ]
      },
      // 版本列表
      businessVersionsList: [],
    };
  },
  created() {
    this.getList();
    businessVersions().then(res=>{
      if(res.code == 200){
        this.businessVersionsList = res.data
      }
    })
  },
  methods: {
    getColor(_props){
      // let _inx = this.hazwasteList.findIndex(_v=>_v.hwType == _props.hwType)
      // if(_inx!=-1){
      //   _inx++
      //   return _inx
      // }
      // return 1 
    },
    /** 查询部门列表 */
    getList() {
      this.loading = true;
      hazwasteList(this.queryParams).then(response => {
        let _id = 0
        response.data.map((_v,_i)=>{
          _id++
          _v.id = _id
          // if(_v.hasOwnProperty('hwBusinessSourceList')){
          //   _v.children = JSON.parse(JSON.stringify(_v.hwBusinessSourceList))
          //   _v.children.map(_a=>{
          //     _id++
          //     _a.id = _id
          //     if(_a.hasOwnProperty('hazardousWasteData')){
          //       _a.children = JSON.parse(JSON.stringify(_a.hazardousWasteData))
          //       _a.children.map(_b=>{
          //         _id++
          //         _b.id = _id
          //       })
          //     }
          //   })
          // }
        })
        this.hazwasteList = response.data;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        hwType: '',
        businessSource: '',
        hwCode: '',
        hwName: '',
        versions: ''
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      this.reset();
      if (row != undefined) {
        this.form.parentId = row.hwDataConfId;
        this.form.sort = row.hasOwnProperty('children')? row.children.length+1:0
      }else{
        this.form.sort = this.hazwasteList.length+1
      }
      this.open = true;
      this.title = "添加危险废物";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.form = JSON.parse(JSON.stringify(row))
      this.open = true;
      this.title = "修改危险废物";
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.hwDataConfId != undefined) {
            hazwasteEdit(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            hazwasteAdd(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm('是否确认删除名称为"' + row.hwType + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return hazwasteDel(row.hwDataConfId);
        }).then(res => {
          this.getList();
          if(res.code == 200){
            this.msgSuccess("删除成功");

          }else{
            this.msgError(res.msg)
          }
        }).catch(function() {});
    }
  }
};
</script>
<style scoped>
  .app-container{
    margin: 20px;
    background-color: #fff;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  }
  .hazwasteDetail {
    width: 100%;height:auto;
  }
  .hazwasteDetail_left{
    width: 250px;
    text-align: center;
  }
  .hazwasteDetail_options{
    width: 100%;height: auto;
  }
  .hazwasteDetail_optionsTitle{
    width: 100%;height: 46px;line-height: 46px;
    display: flex;align-content: center;
    border-bottom: 1px solid #dfe6ec;
  }
  .hazwasteDetail_optionsTitleOptions,.optionsContent_rightOptions{
    width: 12%;
    text-align: center;
  }
  >>>.el-table__expanded-cell{
    padding: 0px;
  }
  .hazwasteDetail_optionsContent{
    width: 100%;height: auto;
    display: flex;align-items: center;
  }
  .optionsContent_left{
    width: 40%;text-align: center;
  }
  .optionsContent_right{
    flex: 1;    
    border-left: 1px solid #dfe6ec;

  }
  .optionsContent_right>div{
    border-bottom: 1px solid #dfe6ec;
  }
  .optionsContent_right>div:last-child{
    border: none;
  }
  .optionsContent_rightRow{
    width: 100%;height: auto;
    display: flex;align-items: center;
    
  }
  .optionsContent_rightOptions{
    height: 46px;line-height: 46px;
    text-align: center;
  }
  >>>.el-table td{
    /* border: none; */
  }
  >>>.el-table__row--striped td{
    /* background: #f5f5f5!important; */
  }
  .line1{
    overflow:hidden;
    text-overflow:ellipsis;
    display:-webkit-box;
    -webkit-line-clamp:1;
    -webkit-box-orient:vertical;
  }
</style>